package solution;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {

    int maxDeep = 0;

    public int maxDepth(TreeNode root) {
        if (null == root) {
            return 0;
        }

        method(root, 1);

        return maxDeep;
    }

    public void method(TreeNode root, int deep) {
        maxDeep = Math.max(maxDeep, deep);

        if (null == root) {
            return;
        }

        if (null != root.left) {
            method(root.left, deep + 1);
        }

        if (null != root.right) {
            method(root.right, deep + 1);
        }
    }
}